﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Data.SqlClient;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.Default.model;

namespace Jxym.wlkc2011.Module.Default.SERVER.module
{
    public partial class MenuAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MsSqlDal<User_TreeMenu> iUtm = new MsSqlDal<User_TreeMenu>();
                PropertyInfo[] fields = typeof(User_TreeMenu).GetProperties();
                List<string> listName = new List<string>();
                List<string> listValue = new List<string>();
                object identity = 0;
                foreach (PropertyInfo property in fields)
                {
                    if (Request.Params[property.Name] != null)
                    {
                        listName.Add("@" + property.Name);
                        listValue.Add(Request.Params[property.Name]);
                    }
                }
                SqlParameter[] parameters = new SqlParameter[listName.Count];
                for (int i = 0; i < listName.Count; i++)
                {
                    parameters[i] = new SqlParameter(listName[i], listValue[i]);
                }
                if (listName.Count > 0)
                {
                    if (Request.Params["id"] != null)
                    {
                        identity = iUtm.Updata(parameters);
                        Response.Write("{'success':true,'count':" + identity + "}");
                    }
                    else
                    {
                        identity = iUtm.Add(parameters);
                        Response.Write("{'success':true,'identity':" + identity + "}");
                    }
                }
                else
                {
                    Response.Write("{'success':false,'msg':'没有发现参数,本次操作终止'}");
                }
            }
        }
    }
}